﻿Imports System
Imports System.Collections.Generic
Imports System.Reflection
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration.Health



Public Class HealthRuleFR
    Inherits SPFeatureReceiver


    Public Overrides Sub FeatureDeactivating(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties)
        'MyBase.FeatureDeactivating(properties)

        Dim a As Assembly = Assembly.GetExecutingAssembly()
        Dim exceptions As IDictionary(Of Type, Exception) = SPHealthAnalyzer.UnregisterRules(a)

        If Not exceptions Is Nothing Then
            Dim logEntry As String = a.FullName
            If exceptions.Count = 0 Then
                logEntry += " All rules were unregistered."
            Else
                Dim pair As KeyValuePair(Of Type, Exception)
                For Each pair In exceptions
                    logEntry += String.Format(" Unregistration failed for type {0}. {1}", _
                                                  pair.Key, pair.Value.Message)
                Next
            End If
            System.Diagnostics.Trace.WriteLine(logEntry)
        End If



    End Sub

    Public Overrides Sub FeatureActivated(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties)
        '   MyBase.FeatureActivated(properties)


        Dim a As Assembly = Assembly.GetExecutingAssembly()

        Dim exceptions As IDictionary(Of Type, Exception) = SPHealthAnalyzer.RegisterRules(a)

        If Not exceptions Is Nothing Then
            Dim logEntry As String = a.FullName
            If exceptions.Count = 0 Then
                logEntry += " All rules were registered."
            Else
                Dim pair As KeyValuePair(Of Type, Exception)
                For Each pair In exceptions
                    logEntry += String.Format(" Registration failed for type {0}. {1}", _
                                                  pair.Key, pair.Value.Message)
                Next
            End If
            System.Diagnostics.Trace.WriteLine(logEntry)
        End If





    End Sub

End Class
